#ifndef UTI_BROADCAST_H_
#define UTI_BROADCAST_H_
#pragma once
#include "sys_config.h"
#include "uti_bar.h"
#include "uti_barseries_broad.h"
using namespace std;



class Broadcast
{
public:
	Broadcast(BarInfo* pbar);

	Broadcast(string stringInst);

	~Broadcast();

	void BroadcastMessage(MarketData *pDepthMarketData);

	void GetSharedMq(BarSeries_broad** &ppbarserbroad/*out*/, unsigned int* pcnt/*out*/);

	bool RenewSharedMq();

private:

	bool InitSharedMQ(unsigned int index, unsigned int sersize, char* suffix);

	void DestroySharedMQ(unsigned int index);

	bool InitSharedSemRecord(unsigned int index, char* suffix);

	void DestroySharedSemRecord(unsigned int index);

	bool InitMutex();

	void DestroyMutex();

	bool CleanSharedsema(unsigned int index);




	typedef struct semrecord{
		HANDLE han;
		bool bactive;
		char semname[50];
	}semrecord;
	bool OpenSharedsema(semrecord* psemrecord);

	bool CloseSharedsema(semrecord* psemrecord);

	bool DeleteCursema(semrecord* pstart_semrec, unsigned int size_semrec, unsigned int curindex_semrec);

	void GetCharName(const char* pname, char* pchar);

	bool GetSecurityAttributes(SECURITY_ATTRIBUTES &securityAttributes);

public:


	//BarInfo m_barinfo;

	string m_stringInst;

private:
	typedef struct SharedMemory
	{
		HANDLE hMapFile_barser;
		PVOID pView_barser;
		unsigned int* pindex_barser;
		BarData* pmq_barser;


		HANDLE hMapFile_semrec;
		PVOID pView_semrec;
		unsigned int* psize_semrec;
		semrecord* pmq_semrec;
		
	}SharedMemory;

	HANDLE m_mutex;

	SharedMemory m_shmarr[4];

	BarSeries_broad* m_pbarserbroad[4];
};



#endif